using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Windows.Forms;

namespace SqlCeViewer.Utility
{
    class Util
    {
        public void ClearAllInputs(System.Windows.Forms.Control.ControlCollection controls)
        {
            foreach (Control control in controls)
            {
                if (control is DigitalTextBox.CombinedDTextBox)
                {
                    ((DigitalTextBox.CombinedDTextBox)control).X_TextBoxValue = 0.0d;
                }

                if (control is DigitalTextBox.CombinedCommonTextBox)
                {
                    DigitalTextBox.CombinedCommonTextBox tempControl = control as DigitalTextBox.CombinedCommonTextBox;

                    if (!tempControl.X_IsCanNotBeClearedValue)
                    {
                        tempControl.X_TextBoxValue = "";
                    }
                }
            }
        }


        public void ShowDialogSubUtil(string className, string typeNamespace)
        {
            try
            {
                typeNamespace += ".";

                Type type = Assembly.GetExecutingAssembly().GetType(typeNamespace + className);
                if (type == null)
                {
                    MessageBox.Show("Invalid type");
                    return;
                }
                object s = Activator.CreateInstance(type);

                type.GetMethod("ShowDialogInTab", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static).Invoke(s, new object[] { });
            }
            catch (Exception ee)
            {
#if DEBUG
                throw ee;

#else
                MessageBox.Show("Call modules failure");
                //MessageBox.Show(ee.InnerException.Message);
#endif
            }

        }
    }
}
